from enums.WidgetType import WidgetType
from .wait.Wait import Wait
from .wait.WaitText import WaitText
from .wait.WaitPic import WaitPic
from .click import *
from .input.InputText import InputText
from .input.InputKeyboard import InputKeyboard
from .variable.VariableSet import VariableSet
from .call.CallScript import CallScript
from .sentence.If import If
from .sentence.For import For
from .sentence.While import While
from .sentence.Break import Break
from .drag.Drag import Drag


class Factory:
    _classes = {
        WidgetType.WAIT.value: Wait,  # 等待
        WidgetType.WAIT_TEXT.value: WaitText,
        WidgetType.WAIT_PIC.value: WaitPic,
        WidgetType.CLICK_POS.value: SingleClickPos,  # 点击位置
        WidgetType.DOUBLE_CLICK_POS.value: DoubleClickPos,
        WidgetType.LONG_PRESS_POS.value: LongPressPos,
        WidgetType.CLICK_TEXT.value: SingleClickText,  # 点击文字
        WidgetType.DOUBLE_CLICK_TEXT.value: DoubleClickText,
        WidgetType.LONG_PRESS_TEXT.value: LongPressText,
        WidgetType.CLICK_PIC.value: SingleClickPic,  # 点击图片
        WidgetType.DOUBLE_CLICK_PIC.value: DoubleClickPic,
        WidgetType.LONG_PRESS_PIC.value: LongPressPic,
        WidgetType.VARIABLE_SET.value: VariableSet,  # 变量设置
        WidgetType.DRAG.value: Drag,  # 拖拽
        WidgetType.INPUT_TEXT.value: InputText,  # 输入
        WidgetType.INPUT_KEYBOARD.value: InputKeyboard,
        WidgetType.CALL_SCRIPT.value: CallScript,  # 调用脚本
        WidgetType.IF.value: If,  # 语句
        WidgetType.FOR.value: For,
        WidgetType.WHILE.value: While,
        WidgetType.BREAK.value: Break
    }

    @staticmethod
    def getByType(widgetType, initType):
        classes = Factory._classes
        if widgetType not in classes.keys():
            raise Exception('widgetType error', widgetType)

        return classes[widgetType](initType)
